package com.harassment.interception.ui.fragments.dialogFragments;

import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;

import com.harassment.interception.R;

public class ConfirmDialog extends DialogFragment {
    public static final String TAG = "ConfirmDialog";
    private OnPositiveClickListener mOnPositiveClickListener;
    private OnNegativeClickListener mOnNegativeClickListener;
    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Activity activity = getActivity();
        if (activity == null) {
            return super.onCreateDialog(savedInstanceState);
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        LayoutInflater layoutInflater = activity.getLayoutInflater();
        builder.setTitle(R.string.confirm_delete_title)
                .setMessage(R.string.confirm_delete_message)
                .setPositiveButton(R.string.positive, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (mOnPositiveClickListener != null) {
                            mOnPositiveClickListener.onPositiveClickListener(dialog, which);
                        }
                    }
                })
                .setNegativeButton(R.string.negative, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (mOnNegativeClickListener != null) {
                            mOnNegativeClickListener.onNegativeClickListener(dialog, which);
                        }
                    }
                });
        return builder.create();
    }

    public void setOnPositiveClickListener(OnPositiveClickListener onPositiveClickListener) {
        mOnPositiveClickListener = onPositiveClickListener;
    }

    public OnNegativeClickListener getOnNegativeClickListener() {
        return mOnNegativeClickListener;
    }

    public void setOnNegativeClickListener(OnNegativeClickListener onNegativeClickListener) {
        mOnNegativeClickListener = onNegativeClickListener;
    }
}
